//
// Created by yangchao on 2022/4/22.
// 14. 最长公共前缀: https://leetcode-cn.com/problems/longest-common-prefix/
//
#include <string>
#include <vector>
using namespace std;

class CommonPrefix {
public:
    string longestCommonPrefix(vector<string>& strs) {
        if (strs.size() == 0) return "";
        string res = strs[0];
        for (int i = 1; i < strs.size(); ++i) {
            int j = 0;
            for (; j < res.size() && strs[i].size(); ++j) {
                if (res[j] != strs[i][j]) break;
            }
            res = res.substr(0,j);
            if (res == " ") return res;
        }
        return res;
    }
};
